package com.itheima.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

@SuppressWarnings("all")
public class Demo2 {
    public static void main(String[] args) {
        //创建一个指定最多线程数量的线程池,注意这里设定的不是初始化值而是实际可达到的最大值
        ExecutorService service = Executors.newFixedThreadPool(10);
        ThreadPoolExecutor poolExecutor = (ThreadPoolExecutor) service;
        int poolSize1 = poolExecutor.getPoolSize();
        System.out.println(poolSize1);

        service.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "在执行");
        });
        service.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "在执行");
        });

        int poolSize2 = poolExecutor.getPoolSize();
        System.out.println(poolSize2);
        service.shutdown();
    }
}
